#!/bin/bash

TAP=tap5

# /24 = 0
# /25 = 128
# /26 = 192
# /27 = 224
# /28 = 240
# /29 = 248
# /30 = 252

SERV_APACHE_DIR="apache2"

if [ $UID != 0 ]; then
    echo "Debe estar logueado como Superusuario para levantar este servicio."
    exit 1
fi

echo "Cargando tablas de rueto"
# Apache pertenece a la red Aquaman
# Tablas de ruteo
# Idem a host C
# Tablas de ruteo
# Salen por R1:
# Red Green Lantern
route add -net 194.210.31.0 netmask 255.255.255.128 gw 194.210.31.2 $TAP

# Red Joker
route add -net 10.58.6.160 netmask 255.255.255.224 gw 194.210.31.2 $TAP

# Red Lex Luthor
route add -net 10.58.5.0 netmask 255.255.255.0 gw 194.210.31.2 $TAP

# Red Magneto
route add -net 10.58.6.128 netmask 255.255.255.224 gw 194.210.31.2 $TAP

# Redes Nightcrawler
route add -net 10.58.7.216 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.220 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.224 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.228 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.232 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.236 netmask 255.255.255.252 gw 194.210.31.2 $TAP
route add -net 10.58.7.240 netmask 255.255.255.252 gw 194.210.31.2 $TAP

#
# Salen por R2:
# Red Emma Frost
route add -net 10.58.7.192 netmask 255.255.255.240 gw 194.210.31.3 $TAP

# Red Flash
route add -net 10.111.25.0 netmask 255.255.255.128 gw 194.210.31.3 $TAP

#
# Salen por R3:
# Red Batman
route add -net 10.58.6.224 netmask 255.255.255.240 gw 194.210.31.4 $TAP

# Red Catwoman
route add -net 10.58.7.128 netmask 255.255.255.192 gw 194.210.31.4 $TAP

#
# Salen por R4:
# Red Quicksilver
route add -net 10.58.6.192 netmask 255.255.255.224 gw 194.210.31.5 $TAP
echo "Listo tablas ruteo"


echo "Inicialización de Servicio Apache"
echo "*********************************"
echo ""
echo "Instalando Servicio"
echo ""
apt-get install -y apache2

echo ""
echo "Configurando Servicio"
echo ""
service $SERV_APACHE_DIR stop

cp ./pagina.html /var/www
cp ./apache2.conf /etc/apache2
wget http://localhost/pagina.html

service $SERV_APACHE_DIR start

echo ""
echo "Fin de Inicialización de Servicio FTP"
echo "*************************************"
